package com.example.eos.mapper;

import com.example.eos.bean.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Select("select commentid, publishid, userid, content, replynum, cmttime from comment where commentid = #{commentid,jdbcType=VARCHAR}")
    Comment findByCommentid(String commentid);

    @Select("select commentid, publishid, userid, content, replynum, cmttime from comment where publishid = #{publishid,jdbcType=VARCHAR} order by cmttime desc")
    List<Comment> findByPublishid(String publishid);

    @Insert("insert into comment (commentid, publishid, userid, content, replynum, cmttime) values (#{commentid,jdbcType=VARCHAR}, #{publishid,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{replynum,jdbcType=INTEGER}, #{cmttime})")
    void save(Comment comment);

    @Update("update comment set content = '' where commentid = #{commentid,jdbcType=VARCHAR}")
    void deleteByCommentid(String commentid);

}
